<?php

/**
 * Index Controller 
 *
 * Index Controller for accounts module
 *
 * @category   App
 * @package    Account
 * @subpackage Account_Index
 * @copyright  Costrategix Technologies
 * @author     Sandeep Manne<sandeep.manne@costrategix.com>
 */


require_once 'AccountController.php';

class Account_IndexController extends AccountController
{
	/* @var $_account Account */ 
	private $_account;
	
	/**
	 * The Constructer for the class
	 */
	public function init()
	{
		parent::init();
		require_once 'Core/Form/Xml.php';
		Core_Form_Xml::loadForm(file_get_contents(APPLICATION_PATH."/modules/account/forms/login.xml"));
		$this->_account = App::getModel('account', 'account');
	}
	
	/**
	 * Signup Action
	 * 
	 * @access public
	 * @return void
	 */
	public function signupAction()
	{
		if (Zend_Auth::getInstance()->hasIdentity()) $this->_redirect('/');
		
		/* @var $form SignupForm  */
		$form = App::getForm('account', 'signup');
		$data = $this->_helper->getFilteredParams();
		
		if ($this->getRequest()->isPost() && $form->isValid($data)) {
			// Compare emails and passwords
			//$errors = $this->_account->validation($data); 
			
			
				$result = $this->_account->createAccount($data);
				$this->_account->login($data['email'], $data['passwd']);
				$this->_redirect('/welcome');
		}
		$this->view->form = $form;
	}
	
	public function loginAction()
	{
		if (Zend_Auth::getInstance()->hasIdentity()) $this->_redirect('/');
		
		$form = App::loadForm("account", "login");
		$this->view->form = $form;
	}
	
	/**
	 * My Account action.
	 * 
	 * @access public
	 * @return void
	 */
	/*public function myAccountAction()
	{
		$identity = Zend_Auth::getInstance()->getIdentity();
		
		require_once("modules/account/forms/myAccountForm.php");
		$form = new myAccountForm();
		
		$accountDetail = $this->_account->getAccount($identity[0]['account_id']);
		
		$form->populate($accountDetail[0]);
		$this->view->headScript()->appendFile('js/account/account.js');
		$this->view->form = $form;
	}*/
	
	/**
	 * Logout Action
	 * 
	 * @access public
	 * @return void
	 */
	public function logoutAction()
	{
		$this->_account->logout();
		$this->_redirect('/');
	}
	
	/**
	 * Welcome Action(Puchase package view) after signup.
	 * 
	 * @access public
	 * @return void
	 */
	public function welcomeAction()
	{
		$this->view->welcome = true;
	}
}